//
//  UCGeometryUtils.cpp
//  AeroMapSDK
//
//  Created by 北京国泰北斗科技有限公司 on 2017/3/10.
//  Copyright © 2017年 北京国泰北斗科技有限公司. All rights reserved.
//

#include "UCGeometryUtils.h"
#import <GoogleMaps/GoogleMaps.h>
#import "UCPolyline.h"

NSMutableArray *_spans = [[NSMutableArray alloc] init];
NSMutableArray *array = [[NSMutableArray alloc] init];

UC_NSArrayOf(UCStyleSpan *) *UCSStyleSpans(UCPath *path,
                                           UC_NSArrayOf(UCStrokeStyle *) *styles,
                                           UC_NSArrayOf(NSNumber *) *lengths,
                                           UCLengthKind lengthKind){
    
    for (UCStrokeStyle *style in styles) {
        GMSStrokeStyle *gmStyle = [style valueForKey:@"strokeStyle"];
        [array addObject:gmStyle];
    }
    
    switch (lengthKind) {
        case UCLengthGeodesic:
        {
            for (GMSStyleSpan *span in GMSStyleSpans([path valueForKey:@"gmPath"], array, lengths, kGMSLengthGeodesic)) {
                UCStyleSpan *mySpan = [[UCStyleSpan alloc] init];
                [mySpan setValue:span forKey:@"styleSpan"];
                [_spans addObject:mySpan];
            }
        }
            break;
        case UCLengthRhumb:
        {
            for (GMSStyleSpan *span in GMSStyleSpans([path valueForKey:@"gmPath"], array, lengths, kGMSLengthRhumb)) {
                UCStyleSpan *mySpan = [[UCStyleSpan alloc] init];
                [mySpan setValue:span forKey:@"styleSpan"];
                [_spans addObject:mySpan];
            }
        }
            break;
        case UCLengthProjected:
        {
            for (GMSStyleSpan *span in GMSStyleSpans([path valueForKey:@"gmPath"], array, lengths, kGMSLengthProjected)) {
                UCStyleSpan *mySpan = [[UCStyleSpan alloc] init];
                [mySpan setValue:span forKey:@"styleSpan"];
                [_spans addObject:mySpan];
            }
        }
            break;
    }
    
    return _spans;

}

CLLocationDistance CalculateTheDistanceOfTheLine(UCPath *path){

    if (path && [path isKindOfClass:[UCPath class]]) {
        return GMSGeometryLength([path valueForKey:@"gmPath"]);
    }
    return 0.0000;
}

double CalculatePolygonArea(UCPath *path){
    
    if (path && [path isKindOfClass:[UCPath class]]) {
        return GMSGeometryArea([path valueForKey:@"gmPath"]);
    }
    return 0.000;
}
